package com.hxd.otc.module.my.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.hxd.otc.R;
import com.hxd.otc.base.BaseAdapter;
import com.hxd.otc.module.my.bean.CurrencyBean;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by lzy on 2018/6/8 0008.
 * description ${TODO}

 */
public class CurrencyAdapter extends BaseAdapter<CurrencyAdapter.SupportCurrencyHolder, CurrencyBean> {
    public CurrencyAdapter(Context context) {
        super(context);
    }

    @Override
    protected void onBindHolder(@NonNull final SupportCurrencyHolder holder, final int position) {
        final CurrencyBean item = getItem(position);
        holder.tvContent.setText(item.getCode());
        holder.tvContent.setSelected(item.isSelected());
        holder.tvContent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                item.setSelected(!item.isSelected());
                notifyItemChanged(position);
            }
        });
    }

    @NonNull
    @Override
    public SupportCurrencyHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new SupportCurrencyHolder(mInflater.inflate(R.layout.item_currency, parent, false));
    }

    static class SupportCurrencyHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_content)
        TextView tvContent;

        SupportCurrencyHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }
}
